<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/percircle.css" />
    <link rel="stylesheet" type="text/css" href="./css/styleold.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>

<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left" tapmode onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">个人信息</div>
        <!-- <a class="aui-pull-right">
        保存
      </a> -->
    </header>
    <div id="list">
        <div class="aui-bar-nav-d"></div>

        <ul class="user-data">
            <li tapmode onclick="">
                头像
                <img src="image/jkd.jpg">
            </li>
            <li>
                昵称
                <span id="nickname">金可贷</span>
            </li>
            <li>
                会员等级
                <span>普通会员</span>
            </li>
            <li>
                我的邀请码
                <span>567805</span>
            </li>
        </ul>
        <ul class="user-data">
            <li>
                真实姓名
                <span id="truename">未实名</span>
            </li>
            <li>
                手机号码
                <span id="mobile">未认证</span>
            </li>
            <li>
                身份证
                <span id="IDCard">未认证</span>
            </li>
            <!-- <li class="aui-list-item-arrow" tapmode onclick="bank_list()"> -->
            <li class="aui-list-item-arrow">
                银行卡
                <span class="text" id="is_hrb" style="color:red">未开通</span>
            </li>
        </ul>
    </div>
    <ul class="user-data">
        <li class="aui-list-item-arrow" tapmode onclick="user_safe()">
            密码安全
        </li>
    </ul>

    <div class="more-list-d" onclick="logout();" id="btnForLogin">退出登录</div>


    <!--    <div class="user-data-btn" onclick="licai_box()">安全退出</div>

   <div class="licai-buy-box-bg">
    <div class="licai-buy-box">
      <h3>提示</h3>
      <p>确定要退出吗？</p>
      <div class="licai-buy-box-btn">
        <a tapmode onclick="user()">确定</a>
        <a class="green" onclick="licai_box_close()">取消</a>
      </div>
    </div>
  </div> -->

</body>
<script type="text/template" id="template">
    <div class="aui-bar-nav-d"></div>

    <ul class="user-data">
        <li tapmode onclick="photo();">
            头像
            <img src="image/jkd.jpg" id="headImg">
        </li>
        <li>
            昵称
            <span>{{=it.nickname}}</span>
        </li>

        <li>
            我的邀请码
            <span>{{=it.rec_code}}</span>
        </li>
    </ul>
    <ul class="user-data">
        <li>
            真实姓名
            <span>{{=it.user_name}}</span>
        </li>
        <li>
            手机号码
            <span>{{=it.mobile}}</span>
        </li>
        <li>
            身份证
            <span>{{=it.idno}}</span>
        </li>
        <li class="aui-list-item-arrow" tapmode onclick="bank_list('{{=it.bankname}}')">
            银行卡
            <span class="text" id="is_hrb" style="color:red">未开通</span>
        </li>

    </ul>
</script>
<script type="text/javascript">
    apiready = function() {

        updateData();

        // setUserInfo();
    }

    // 更新数据
    function updateData() {
        // 进度提示框
        api.showProgress({
            title: '努力加载中...',
            text: '请稍等...',
            modal: false
        });
        var userid = $api.getStorage('userid');
        // 如果已登录 获取数据
        if (userid) {
            api.ajax({
                url: webAddress + '/index.php?ctl=app_user_center&act=userdetailinfo',
                method: 'post',
                data: {
                    values: {
                        id: userid,
                    },
                }
            }, function(ret, err) {
                if (ret) {
                    // 关闭下拉刷新控件
                    api.refreshHeaderLoadDone();
                    api.hideProgress();
                    if (ret.status == 0) {
                        alert(ret.info);
                        return false;
                    } else {

                        // alert(JSON.stringify(ret));
                        // // 用户昵称
                        // var user_name = ret.user.user_name;
                        // $api.setStorage('user_name', user_name);
                        // // 用户手机号
                        var mobile = ret.user.mobile;
                        $api.setStorage('mobile', mobile);
                        $api.setStorage('user_name_true', ret.user.user_name); // 此项存储仅用于找回交易密码前的身份认证 forget_deal_password.html
                        $api.setStorage('idno', ret.user.idno);
                        // userInfo数据
                        var data = ret.user;
                        var nickname = $api.getStorage('user_name');
                        var path = ret.user.avatar;
                        data['nickname'] = nickname;
                        if (data['user_name'] == null) {
                            data['user_name'] = '未实名'
                        }
                        if (data['idno'] == null) {
                            data['idno'] = '未认证'
                        }
                        if (data['mobile'] == null) {
                            data['mobile'] = '未认证'
                        }

                        // 调用模板函数
                        templateFun(data, path);
                    }
                } else {
                    alert(err.msg);
                    // 关闭下拉刷新控件
                    api.refreshHeaderLoadDone();
                    // 关闭加载状态控件
                    api.hideProgress();
                }
            });
        } else {
            // 关闭下拉刷新控件
            api.refreshHeaderLoadDone();
            // 关闭加载状态控件
            api.hideProgress();
            templateFun();
        }
    };

    // 模板赋值函数
    function templateFun(data, path) {
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var user = $api.byId('list');
        $api.html(user, html);

        if (path != "") {
            var p = webAddress + path;
            $("#headImg").attr('src', p);
        }

        var is_hrb = $api.getStorage('is_hrb');
        if (is_hrb == 1) {
            $("#is_hrb").css('color', 'green');
            $("#is_hrb").text('已开通');
        }
    }

    // 自动加载用户资料
    function setUserInfo() {
        var mobileM = $api.getStorage('mobileM');
        alert(mobileM);
        var mobileEle = $api.byId('mobile');
        mobileEle.value = mobileM;

        var user_name = $api.getStorage('user_name');
        var nicknameEle = $api.byId('nickname');
        nicknameEle.value = user_name;
    }

    function licai_box_close() {
        $(".licai-buy-box-bg").hide();
    }

    function licai_box() {
        $(".licai-buy-box-bg").show();
    }

    function user() {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'user',
            url: './user.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            }
        });
    };

    function user_safe() {

        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'user_safe',
            url: './user_safe.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            }
        });
    };

    function bank_list(bank) {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'bank_list',
            url: './bank_list.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            },
            pageParam: {
                bank: bank,
            }
        });
    };


    function logout() {
        var userid = $api.getStorage('userid');
        api.confirm({
            title: '提示',
            msg: '是否登出?',
            buttons: ['确定', '取消']
        }, function(ret, err) {
            if (ret) {
                if (ret.buttonIndex == 1) {
                    api.ajax({
                        url: webAddress + '/index.php?ctl=app_user_center2&act=set_apns_code',
                        method: 'post',
                        data: {
                            values: {
                                apns_code: null,
                                id: userid
                            }
                        }
                    }, function(ret, err) {
                        // alert( JSON.stringify( ret ) );
                        $api.setStorage('registrationId', null);
                        $api.setStorage('userid', '');
                        $api.setStorage('mobile', '');
                        // 提示退出成功
                        api.toast({
                            msg: '退出成功!',
                            duration: 1500,
                            location: 'middle'
                        });

                        var setSele = 'randomSwitchBtn(0);';
                        api.execScript({
                            name: 'root',
                            script: setSele,
                        });
                        api.closeWin();
                    });

                }
            } else {}
        });
    }



    function photo() {

        api.actionSheet({
            // title: '底部弹出框测试',
            cancelTitle: '取消',
            // destructiveTitle: '红色警告按钮',
            buttons: ['拍照', '从手机上传照片']
        }, function(ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                //拍照
                photograph('camera');
            } else if (index == 2) {
                //从手机上传
                photograph('library');

            }
        });

    }

    function photograph(temp) {

        api.getPicture({
            sourceType: temp,
            encodingType: 'jpg',
            mediaValue: 'pic',
            destinationType: 'url',
            allowEdit: true,
            quality: 50,
            targetWidth: 100,
            targetHeight: 100,
            saveToPhotoAlbum: false
        }, function(ret, err) {
            if (ret) {
                //  alert(JSON.stringify(ret));
                picUrl = ret.data;
                upPic(picUrl);
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    function upPic(picUrl) {
        if (picUrl == '') {
            return;
        }

        var userid = $api.getStorage('userid');
        // alert(picUrl);
        // alert(userid);

        api.ajax({
            url: webAddress + '/index.php?ctl=avatar&act=upload',
            method: 'post',
            data: {
                values: {
                    user_id: userid,
                },
                files: {
                    avatar_file: picUrl
                }
            }
        }, function(ret, err) {
            if (ret) {
                var src = webAddress + ret.middle_url;
                $("#headImg").attr('src', src);

                api.execScript({
                    name: 'root',
                    script: 'randomSwitchBtn(2)'
                });



            } else {
                alert(JSON.stringify(err.msg));
            }
        });

    }


    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
